package com.maximporges.riatest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;

public class Main
{
   /**
    * @param args
    * @throws FileNotFoundException 
    * @throws Exception
    */
   public static void main(String[] args) throws FileNotFoundException
   {
      if (args.length < 1)
      {
         throw new RuntimeException("The absolute file path to the properties file containing the configuration details was not specified.");
      }
      else
      {
         InputStream configStream = new FileInputStream(new File(args[0]));
         execute(configStream);
      }
   }
   
   public static void execute(InputStream configurationPropertiesStream)
   {
      try
      {
         Properties configProperties = new Properties();
         configProperties.load(configurationPropertiesStream);
         Configuration configuration = new Configuration().assemble(configProperties);
         Integration integration = new IntegrationFactory().newIntegration(configuration);
         new ExecutionWrapper(System.in, System.out, integration).execute();
      }
      catch (Exception e)
      {
         e.printStackTrace(System.out);
         System.exit(1);
      }      
   }
}
